//
//  QQRequestManager+handle.m
//  LClass
//
//  Created by 严军 on 16/5/29.
//  Copyright © 2016年 YanJun. All rights reserved.
//

#import "QQRequestManager+handle.h"

@implementation QQRequestManager (handle)

#pragma --mark NSUserDefaults 

-(void)SET_userInfo:(NSDictionary*)infoDic
{
    [[NSUserDefaults standardUserDefaults] setObject:infoDic forKey:@"USER_INFO"];
}

-(NSDictionary*)GET_userInfo
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"USER_INFO"];
}


#pragma --mark NETREQUEST

/**
 *  登录
 *  @param parameters username/password
 *  @param success  default
 *  @param failure  default
 *
 *  @return default
 */
-(NSURLSessionDataTask *)GET_loginWithParameters:(id)parameters success:(void(^)(NSURLSessionDataTask* task,id responseObject)) success failure:(void(^)(NSURLSessionDataTask* task,NSError *error)) failure
{
    NSString* URLString = URL_login;
    
    void(^preSuccess)(NSURLSessionDataTask* ,id )=^(NSURLSessionDataTask* task,id responseObject)
    {
        //请求成功，数据预处理
        success(task,responseObject);
        NSDictionary* userInfoDic=[responseObject objectForKey:@"user"];
        [self SET_userInfo:userInfoDic];
        
        //跟新相关的UI
        
        //跳转页面
    };
    
    void(^preFailure)(NSURLSessionDataTask*,NSError*)=^(NSURLSessionDataTask* task,NSError *error){
    
        failure(task,error);
    };
    
    NSURLSessionDataTask* tempURLSessionDataTask=[self GET:URLString parameters:parameters showHUD:YES success:preSuccess failure:preFailure];
    
    return tempURLSessionDataTask;
    
}

/**
 *  注册
 *  @param parameters username/password/phone
 *  @param success  default
 *  @param failure  default
 *
 *  @return default
 */
-(NSURLSessionDataTask *)GET_registerWithParameters:(id)parameters success:(void(^)(NSURLSessionDataTask* task,id responseObject)) success failure:(void(^)(NSURLSessionDataTask* task,NSError *error)) failure
{
    NSString* URLString = URL_register;
    
    void(^preSuccess)(NSURLSessionDataTask* ,id )=^(NSURLSessionDataTask* task,id responseObject)
    {
        //请求成功，数据预处理
        success(task,responseObject);
    };
    
    void(^preFailure)(NSURLSessionDataTask*,NSError*)=^(NSURLSessionDataTask* task,NSError *error){
        
        failure(task,error);
    };
    
    NSURLSessionDataTask* tempURLSessionDataTask=[self GET:URLString parameters:parameters showHUD:YES success:preSuccess failure:preFailure];
    
    return tempURLSessionDataTask;

}

/**
 *  考勤数据
 *  @param parameters className/Type
 *  @param success  default
 *  @param failure  default
 *
 *  @return default
 */
-(NSURLSessionDataTask *)GET_kaoQinDataWithParameters:(id)parameters success:(void(^)(NSURLSessionDataTask* task,id responseObject)) success failure:(void(^)(NSURLSessionDataTask* task,NSError *error)) failure
{
    NSString* UrlString=URL_kaoqinData;
    
    void(^preSuccess)(NSURLSessionDataTask* task,id responseObject)=^(NSURLSessionDataTask* task,id responseObject)
    {
        success(task,responseObject);
    };
    
    void(^preFailure)(NSURLSessionDataTask* task,NSError *error)=^(NSURLSessionDataTask* task,NSError *error)
    {
        failure(task,error);
    };
    
    NSURLSessionDataTask* tempURLSessionDataTask=[self GET:UrlString parameters:parameters success:preSuccess failure:preFailure];

    return tempURLSessionDataTask;
}


@end
